<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./plugins/vue/dist/vue.min.js"></script>
    <script src="./plugins/axios/dist/axios.min.js"></script>
    <script src="./js/common.js"></script>

</head>
<body>
    <h1 id="app"></h1>
</body>
<script>
    new Vue({
        el:"#app",
        data:{},
        methods:{},
        mounted(){
            let param = getUrlParam();
            console.debug(param.code);
            //发起请求 获取access_token  参数 code appid appsercet
            // 不适合在前端直接发起获取  access_token  会暴露  appid appsercet
           /*
                1.把code 发送给后台
                2.后台使用code 以及其他参数 发起请求
            */
            this.$http.get("/wxuser/wxcode?code="+param.code).then(res=>{
                let {success,message,resultObj} = res.data;
                if(success){
                    //跳转到首页，把token放到localStorage
                    localStorage.setItem("token",resultObj.token)
                    //把JSON对象 转换为JSON字符串
                    let stringify = JSON.stringify(resultObj.user);
                    localStorage.setItem("user",stringify)
                    //跳转
                    location.href="/index.html"
                }else {
                    // return  new AjaxResult("绑定用户").setResultObj("/binder.html");
                    // 跳转到 绑定页面
                    location.href=resultObj;

                }

            })

        }

    })


</script>

</html>